package com.chapter02;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

public class TestConnection5 {
    public static void main(String[] args) throws SQLException, ClassNotFoundException, IllegalAccessException, InstantiationException, IOException {

        // todo 准备连接数据库的要素
//        String driverClazz = "com.mysql.jdbc.Driver";
//        String url = "jdbc:mysql://127.0.0.1:3306/myschool";
//        String userName = "root";
//        String userPwd = "root";

        InputStream inputStream = TestConnection5.class
                .getClassLoader().getResourceAsStream("jdbc.properties");

        Properties properties = new Properties();
        properties.load(inputStream);

       String driverClazz = properties.getProperty("driverClazz");
       String url = properties.getProperty("url");
       String userName = properties.getProperty("userName");
       String userPwd = properties.getProperty("userPwd");



        // todo 通过反射的方式，创建一个驱动
        Class.forName(driverClazz);

        // todo 通过dirverManager来获取连接对象
        Connection connection = DriverManager.getConnection(url, userName, userPwd);

        // todo 输出连接对象
        System.out.println(connection.getClass().getName());
    }
}
